import java.util.*;  
  
public class PolynomialSum {  
    static class Term {  
        int coef;  
        int exp;  
  
        public Term(int coef, int exp) {  
            this.coef = coef;  
            this.exp = exp;  
        }  
  
        @Override  
        public String toString() {  
            return coef + " " + exp;  
        }  
    }  
  
    public static List<Term> readPolynomial() {  
        Scanner scanner = new Scanner(System.in);  
        int numTerms = scanner.nextInt();  
        List<Term> terms = new ArrayList<>();  
        for (int i = 0; i < numTerms; i++) {  
            int coef = scanner.nextInt();  
            int exp = scanner.nextInt();  
            terms.add(new Term(coef, exp));  
        }  
        scanner.close();  
        return terms;  
    }  
  
    public static List<Term> addPolynomials(List<Term> poly1, List<Term> poly2) {  
        Map<Integer, Integer> sumMap = new HashMap<>();  
        for (Term term : poly1) {  
            sumMap.put(term.exp, sumMap.getOrDefault(term.exp, 0) + term.coef);  
        }  
        for (Term term : poly2) {  
            sumMap.put(term.exp, sumMap.getOrDefault(term.exp, 0) + term.coef);  
        }  
  
        List<Term> sum = new ArrayList<>();  
        for (Map.Entry<Integer, Integer> entry : sumMap.entrySet()) {  
            if (entry.getValue() != 0) {  
                sum.add(new Term(entry.getValue(), entry.getKey()));  
            }  
        }  
  
        // Sort the sum by exponent in descending order  
        sum.sort((t1, t2) -> Integer.compare(t2.exp, t1.exp));  
  
        return sum;  
    }  
  
    public static void printPolynomial(List<Term> poly) {  
        if (poly.isEmpty()) {  
            System.out.println("0 0");  
            return;  
        }  
  
        for (int i = 0; i < poly.size(); i++) {  
            System.out.print(poly.get(i));  
            if (i < poly.size() - 1) {  
                System.out.print(" ");  
            }  
        }  
        System.out.println();  
    }  
  
    public static void main(String[] args) {  
        List<Term> poly1 = readPolynomial();  
        List<Term> poly2 = readPolynomial();  
        List<Term> sumPoly = addPolynomials(poly1, poly2);  
        printPolynomial(sumPoly);  
    }  
}